<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script>

function confirmDelete() {
	var categories = $('listForm').tl_tests;
	for (i = 0; i < cl_categories.length; i++) {
		if (categories[i].checked) {
			return confirm('Bạn có chắc muốn xóa đề thi này?');
		}
	}
	alert('Bạn cần chọn ít nhất 1 thể loại.');
	return false;
}

</script>

${message}

<form action="${scriptPath}" id="listForm">
<input type="hidden" name="action" value="test.list" />

<c:if test="${sessionScope.login}">
	<div class="toolbar">
		<button name="tl_submit" value="create" type="submit">Thêm</button>
		<button name="tl_submit" value="delete" type="submit" onclick="return validateDelete();">Xóa</button>
	</div>
</c:if>

<div class="navigator">
<c:choose>
	<c:when test="${page > 1}">
		<a href="${scriptPath}?action=test.list&page=1">&lt;&lt;</a>
		<a href="${scriptPath}?action=test.list&page=${page-1}">&lt;</a>
	</c:when>
	<c:otherwise>
		&lt;&lt; 
		&lt; 
	</c:otherwise>
</c:choose>

Trang ${page}

<c:choose>
	<c:when test="${page < pageCount}">
		<a href="${scriptPath}?action=test.list&page=${pageCount}">&gt;&gt;</a>
		<a href="${scriptPath}?action=test.list&page=${pageCount+1}">&gt;</a>
	</c:when>
	<c:otherwise>
		&gt;
		&gt;&gt;
	</c:otherwise>
</c:choose>
</div>

<table>
<tr>
	<td>&nbsp;</td>
	<td>Tên</td>
	<td>Mô tả</td>
	<td>Thể loại</td>
	<td>Tác giả</td>
	<td>Ngày tạo</td>
</tr>
<c:forEach items="${tests}" var="test">
<tr>
	<td><input type="checkbox" name="tl_tests" value="${test.id}"></input></td>
	<td><a href="${scriptPath}?action=test.view&id=${test.id}">${test.name}</a></td>
	<td>${test.description}</td>
	<td><a href="${scriptPath}?action=test.list&category=${test.category.id}">
		${test.category.name}
	</a></td>
	<td><a href="${scriptPath}?action=test.list&author=${test.author.id}">
		${test.author.name}
	</a></td>
	<td>${test.createDate}</td>
</tr>
</c:forEach>
<tr>
</tr>
</table>

<div class="navigator">
<c:choose>
	<c:when test="${page > 1}">
		<a href="${scriptPath}?action=test.list&page=1">&lt;&lt;</a>
		<a href="${scriptPath}?action=test.list&page=${page-1}">&lt;</a>
	</c:when>
	<c:otherwise>
		&lt;&lt; 
		&lt; 
	</c:otherwise>
</c:choose>

Trang ${page}

<c:choose>
	<c:when test="${page < pageCount}">
		<a href="${scriptPath}?action=test.list&page=${pageCount}">&gt;&gt;</a>
		<a href="${scriptPath}?action=test.list&page=${pageCount+1}">&gt;</a>
	</c:when>
	<c:otherwise>
		&gt;
		&gt;&gt;
	</c:otherwise>
</c:choose>
</div>

<c:if test="${sessionScope.login}">
	<div class="toolbar">
		<button name="tl_submit" value="create" type="submit">Thêm</button>
		<button name="tl_submit" value="delete" type="submit" onclick="return validateDelete();">Xóa</button>
	</div>
</c:if>

</form>